package com.finger.forest.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.finger.forest.CollectionRoadDetailActivity;
import com.finger.forest.R;
import com.finger.forest.model.CollectionRoadModel;

import java.util.List;

/**
 * @author jzj
 * @date 2021/1/27
 * @desc
 */
public class CollectionListRoadAdapter extends BaseQuickAdapter<CollectionRoadModel, BaseViewHolder> {

    private static final String TAG = "CollectionListRoad";

    private Context context;

    public CollectionListRoadAdapter(int layoutResId, @Nullable List<CollectionRoadModel> data, Context context) {
        super(layoutResId, data);
        this.context = context;
    }

    @Override
    protected void convert(BaseViewHolder helper, CollectionRoadModel item) {
        TextView tv_road_name = helper.getView(R.id.tv_road_name);
        tv_road_name.setText(item.getRoadName());

        TextView tvRoadType = helper.getView(R.id.tvRoadType);
//        1公路、2城市道路、3厂矿道路、4林区道路
        String type = item.getRoadType();
        String typeStr = "";
        if (type.equals("1")) {
            typeStr = "公路";
        }

        if (type.equals("2")) {
            typeStr = "城市道路";
        }

        if (type.equals("3")) {
            typeStr = "厂矿道路";
        }

        if (type.equals("4")) {
            typeStr = "林区道路";
        }
        tvRoadType.setText(typeStr);

        TextView tvRemark = helper.getView(R.id.tvRemark);
        tvRemark.setText(item.getRemark());

        TextView tvLeave = helper.getView(R.id.tvLeave);
        String leave = item.getRoadLeave();
        String leaveStr = "";
        if (leave.equals("1")) {
            leaveStr = "一级";
        }

        if (leave.equals("2")) {
            leaveStr = "二级";
        }

        if (leave.equals("3")) {
            leaveStr = "三级";
        }

        if (leave.equals("4")) {
            leaveStr = "四级";
        }
        tvLeave.setText(leaveStr);

        //查看详情
        Button btn_road_detail = helper.getView(R.id.btn_road_detail);
        btn_road_detail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, CollectionRoadDetailActivity.class);
                intent.putExtra("id",item.getId());
                context.startActivity(intent);
            }
        });

    }

}
